package com.wyh.cloud.service.impl;

import com.wyh.cloud.service.IMessagePro;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author wyh
 * @version 1.0
 * @date 2021/11/19 17:16
 */
@EnableBinding(Source.class) //定义消息推送的管道
public class IMessageProIMpl implements IMessagePro {

    @Resource
    private MessageChannel output;

    @Override
    public String send() {

        String serial = UUID.randomUUID().toString();
        //调用消息构建器构建消息，使用信道发送，管道为source
        output.send(MessageBuilder.withPayload(serial).build());

        return serial;
    }
}
